package com.example.demo.com.example.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JDKMeipo implements InvocationHandler {

    private Object person;

    public Object getInstance(Object person){
        this.person = person;

        //代理类创建第三方实例 1ClassLoader,2类的所有接口方法，当前对象
        return Proxy.newProxyInstance(person.getClass().getClassLoader(),person.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object obj = method.invoke(this.person,args);
        after();
        return null;
    }


    private void after() {
        System.out.println("可以结婚了");

    }

    private void before() {

        System.out.println("我是媒婆，大家好");
        System.out.println("我要物色了，漂亮的");
    }
}
